package com.siren.tank.group.image;

import com.siren.tank.*;
import com.siren.tank.group.Bullet;

import java.awt.*;

/**
 * @author : wangjichao
 * @description:
 * @date : 2020/7/29 10:33
 */
public class GoodBullet extends Bullet {

     public GoodBullet(int x, int y, Dir dir, Group group) {
        super(x, y, dir);
        this.setGroup(group);
    }

    @Override
    public void paint(Graphics g) {
        if (!this.live) {
            GameModel.getInstance().remove(this);
            return;
        }
        switch (dir) {
            case LEFT:
                g.drawImage(ResourceMgr.bulletL, x, y, null);
                break;
            case RIGHT:
                g.drawImage(ResourceMgr.bulletR, x, y, null);
                break;
            case UP:
                g.drawImage(ResourceMgr.bulletU, x, y, null);
                break;
            case DOWN:
                g.drawImage(ResourceMgr.bulletD, x, y, null);
                break;
        }
        move();
    }


    private void move() {
        switch (dir) {
            case LEFT:
                x -= SPEED;
                break;
            case RIGHT:
                x += SPEED;
                break;
            case UP:
                y -= SPEED;
                break;
            case DOWN:
                y += SPEED;
                break;
            default:
                break;
        }

        if (x < 0 || y < 0 || x > TankFrame.WIDTH || y > TankFrame.HEIGHT) {
            this.live = false;
        }
    }
}
